package com.veo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.lang.ref.ReferenceQueue;
import java.util.UUID;

@Controller
public class UploadController {


    @RequestMapping("/uploadFile")
    public String uploadFile(String pname, MultipartFile uploadFile, HttpServletRequest request){
        String fileName = "";

        String uploadFileName = uploadFile.getOriginalFilename();
        String extendName = uploadFileName.substring(uploadFileName.lastIndexOf("."));
        String uuid = UUID.randomUUID().toString().replace("-","").toUpperCase();

        if (StringUtils.hasLength(pname)){
            fileName = uuid + "-"+ pname + extendName;
        }else {
            fileName = uuid + extendName;
        }

        return "success";
    }

}
